<?php
    session_start();
    include_once '../conexion/Conexion.php';
    $con = new Conexion();
    
    $tc = $_REQUEST['tc'];
    
    if($tc == 1){
        
        $oida = $_REQUEST['oida'];
        $ingreso = $_REQUEST['ingreso'];
        $docpac = $_REQUEST['docpac'];
        $tipodoc = $_REQUEST['tipodoc'];
        $obs = $_REQUEST['obs'];

        $update = "update hcnarcfispac
                   set pacnumdoc ='".$docpac."',
                       adnIngreso = '".$ingreso."',
                       gentipdocdg = '".$tipodoc."',
                       hafobserva = '".$obs."',
                       haffecha1 = GETDATE(),
                       usuoid = '".$_SESSION['usuario']."'
                       WHERE oid =".$oida;
        $con->query($update);
        
    }else if($tc == 2){
        
        $docpac2 = $_REQUEST['docpac'];
        
        $select = "select HC.oid as oid,HC.adnIngreso,hafnombarch,haffecha1,hafobserva,ltrim(rtrim(usu_nombres)) +' '+ ltrim(rtrim(usu_apellidos)) as nombres,
                           gentipdocdg.gdgdescripci,GENTERCER.TERNUMDOC
                   from hcnarcfispac AS HC LEFT OUTER JOIN usuario on HC.usuoid = usuario.usu_oid
                                      LEFT OUTER JOIN gentipdocdg on HC.gentipdocdg = gentipdocdg.oid
                                      LEFT OUTER JOIN ".$con->getReal()."..ADNINGRESO on HC.adnIngreso = ADNINGRESO.AINCONSEC
                                      LEFT OUTER JOIN ".$con->getReal()."..GENDETCON ON ADNINGRESO.GENDETCON = GENDETCON.OID
                                      LEFT OUTER JOIN ".$con->getReal()."..GENTERCER ON GENDETCON.GENTERCER1 = GENTERCER.OID
                   where pacnumdoc = '".$docpac2."'
                   order by HC.adnIngreso asc";
        $res = $con->query($select);
        
        while($res2 = mssql_fetch_array($res)){
            $lista[] = $res2;
        }
        
        print_r(json_encode($lista));
        
    }else if($tc == 3){
        
        $oid = $_REQUEST['oid'];
        
        $delete = "delete from hcnarcfispac where oid = ".$oid;
        $con->query($delete);
        
        print_r(json_encode(array('men'=>'El archivo se elimino correctamente')));
        
    }
    
    
    $con->cerrarConexion();
?>
